package common

type BusinessCode int

type Result struct {
	Code    BusinessCode `json:"code"`
	Message string       `json:"message"`
	Data    any          `json:"result"`
}

func NewResult() *Result {
	return &Result{
		Code:    0,
		Message: "",
		Data:    nil,
	}
}

func (r *Result) Success(data any) *Result {
	if data == nil {
		data = make([]any, 0)
	}
	r.Code = 0
	r.Message = "success"
	r.Data = data
	return r
}

func (r *Result) Fail(code BusinessCode, message string) *Result {
	r.Code = code
	r.Message = message
	r.Data = make([]any, 0)
	return r
}
